package com.example.tellwin.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tellwin.R;
import com.example.tellwin.question.act.WriteBroadActivity;

/**
 * @author : LinZePeng
 * @date : 2020/12/15
 * @Describe ：
 **/
public class SeekBarPopuwindow extends PopupWindow {

    OnSeekBarConfirmListener onSeekBarConfirmListener;
    Context context;
    SeekBar seekBar;
    TextView sizeTv;
    Button confirmBtn;
    int max = 100;
    int progress = 10;

    public SeekBarPopuwindow(Context context, int max, int progress, OnSeekBarConfirmListener onSeekBarConfirmListener) {
        super(context);
        this.onSeekBarConfirmListener = onSeekBarConfirmListener;
        this.context = context;
        this.max = max;
        this.progress = progress;
        init();
    }

    private void init() {
        View view = LayoutInflater.from(context).inflate(R.layout.seekbar_pop, null);
        seekBar = view.findViewById(R.id.seek_bar);
        sizeTv = view.findViewById(R.id.size_tv);
        confirmBtn = view.findViewById(R.id.confrim_btn);
        seekBar.setMax(max);
        seekBar.setProgress(progress);
        confirmBtn.setOnClickListener(v -> {
            onSeekBarConfirmListener.onSeekBarConfirm(seekBar.getProgress());
            dismiss();
        });
        setContentView(view);
        setBackgroundDrawable(context.getResources().getDrawable(R.color.transparent));
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setOutsideTouchable(true);
    }

    public void show(View view) {
        showAsDropDown(view);
    }

    public interface OnSeekBarConfirmListener {
        void onSeekBarConfirm(int size);
    }
}
